// 路由拦截
import { patchRouter } from "../utils/index.js";
import { turnApp } from '../router/routerHandle.js';

// 重写window的路由跳转
export const rewriteRouter = () => {
  // pushState 和 replaceState 都可以通过方法的形式调用
  window.history.pushState = patchRouter(
    window.history.pushState,
    "micro_push"
  );
  window.history.replaceState = patchRouter(
    window.history.replaceState,
    "micro_replace"
  );
  window.addEventListener('micro_push', turnApp);
  window.addEventListener('micro_replace', turnApp);

  window.onpopstate = function (){
    turnApp();
  } // 监控浏览器的前进后退
};
